package com.lovo.Atm;

import com.lovo.Util;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Save extends JPanel implements ActionListener {
    private JButton backImg;
    private JButton saveImg;
    private JLabel note;
    private JTextField printSave;
    private Home frame;
    private Icon saveBtn = Util.iconImg("/images/buttonSave.jpg");
    private Icon backBtn = Util.iconImg("/images/buttonOff.jpg");


    public Save(Home frame) {
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);


        //返回按钮，菜单界面
        backImg = new JButton(backBtn);
        backImg.setBounds(870, 300, 140, 50);
        this.add(backImg);
        backImg.addActionListener(this);

        //存款按钮
        saveImg = new JButton(saveBtn);
        saveImg.setBounds(0, 300, 140, 50);
        this.add(saveImg);
        saveImg.addActionListener(this);

        //存款文字提示
        note = new JLabel("请输入存款金额：");
        note.setBounds(300, 230, 300, 30);
        note.setFont(new Font("宋体", Font.BOLD, 20));
        this.add(note);

        //存款文本框
        printSave = new JTextField();
        printSave.setBounds(600, 230, 100, 30);
        printSave.setFont(new Font("宋体", Font.BOLD, 20));
        this.add(printSave);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == backImg) {
            frame.switchPanel("menu");
        }
        if (e.getSource() == saveImg) {
            //存入的金额
            double b = Double.valueOf(printSave.getText());
            double a = frame.getLoginUser().getBlance();
            frame.getFindPanel().set(a+b);

            JOptionPane.showMessageDialog(this,"存款成功！");
            frame.switchPanel("menu");
        }
    }

}
